package com.asset.dispoal.extension.strategy.command;

import com.asset.dispoal.extension.domain.dto.RolePermissionDTO;
import com.asset.dispoal.extension.strategy.BaseDataPowerStrategyServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.strategy.StrategyHandlerParam;
import tech.mhuang.pacebox.core.strategy.StrategyHandlerResult;

import java.util.Collections;
import java.util.List;

/**
 * 自定义部门
 *
 * @author mhuang
 * @since 1.0.0
 */
@Component
@Slf4j
public class CustomDepartmentDataPowerStrategyServer implements BaseDataPowerStrategyServer {

    @Override
    public StrategyHandlerResult<String> strategy(StrategyHandlerParam<RolePermissionDTO> strategyHandlerParam) {
        RolePermissionDTO dto = strategyHandlerParam.getData();
        String sqlHeader = "select 2 from sys_role_auth_depart power ,  sys_department_user dep , sys_role_user role " +
                "  where  power.depart_id = dep.department_id and power.role_id = role.role_id" +
                " and role.role_id = '" + dto.getRoleId() + "'" +
                " and dep.user_id = " + dto.getCarry() +
                " and role.user_id = '" + dto.getUserId() + "'";
        return new StrategyHandlerResult<>(true, sqlHeader);
    }

    @Override
    public List<String> event() {
        return Collections.singletonList("2");
    }
}
